package com.zh.demo04.controller;

import com.zh.demo04.common.ApiResult;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.UUID;

import static com.zh.demo04.common.ApiResult.success;


/**
 * 要权限才能访问
 *
 * @author ZH
 * @Date 12:31 2020/4/17
 */
@Slf4j
@RestController
@RequestMapping("/api")
public class BookController {

    @GetMapping("/book")
    public ApiResult<List<?>> bookList(String sign) {
        log.info("call bookList() ... sign = {}", sign);

        var xyj = new Book("西游记", "师徒四人西天取经");
        var sgyy = new Book("三国演义", "三国之间的纷乱故事");
        var shz = new Book("水浒传", "一群好汉的江湖事迹");
        var hlm = new Book("红楼梦", "晚清家族内部琐事");

        return success(List.of(xyj, sgyy, shz, hlm));
    }

    @GetMapping("/vip/book")
    public ApiResult<List<?>> vipBookList(String sign) {
        log.info("call vipBookList() ... sign = {}", sign);

        var xyj = new Book("西游记(VIP)", "师徒四人西天取经");
        var sgyy = new Book("三国演义(VIP)", "三国之间的纷乱故事");
        var shz = new Book("水浒传(VIP)", "一群好汉的江湖事迹");
        var hlm = new Book("红楼梦(VIP)", "晚清家族内部琐事");

        return success(List.of(xyj, sgyy, shz, hlm));
    }

    @Getter
    static class Book {
        private String id;
        private String title;
        private String content;

        public Book() {
        }
        public Book(String title, String content) {
            this.id = UUID.randomUUID().toString().substring(24);
            this.title = title;
            this.content = content;
        }
    }
}
